//
//  XJAfterSaleHeaderView.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/6/19.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJAfterSaleHeaderView.h"

@interface XJAfterSaleHeaderView()
@property(nonatomic, strong) UIView *div1;
@property(nonatomic, strong) UIImageView *iconIv;
@property(nonatomic, strong) UILabel *nameLb;//标题lb
@property(nonatomic, strong) UILabel *countLb; //数量Lb


@property(nonatomic, strong) UIView *div2;
@property(nonatomic, strong) UILabel *questionLb; //问题描述lb


@end
@implementation XJAfterSaleHeaderView

- (UIView *)div1 {
    if (!_div1) {
        _div1 = [UIView new];
    }
    return _div1;
}
- (UIImageView *)iconIv {
    if (!_iconIv) {
        _iconIv = [UIImageView new];
        _iconIv.image = [UIImage imageNamed:@"AppIcon"];
    }
    return _iconIv;
}

- (UILabel *)nameLb {
    if (!_nameLb) {
        _nameLb = [UILabel new];
        _nameLb.text = @"iOS测试商品";
    }
    return _nameLb;
}
- (UILabel *)countLb {
    if (!_countLb) {
        _countLb = [UILabel new];
        _countLb.text = @"数量: 1";
    }
    return _countLb;
}


- (UIView *)div2{
    if (!_div2) {
        _div2 = [UIView new];
    }
    return _div2;
}
- (UILabel *)questionLb {
    if (!_questionLb) {
        _questionLb = [UILabel new];
        _questionLb.text = @"问题描述";
        _questionLb.font = XJFONTSET_R(18.0);
    }
    return _questionLb;
}

- (YYTextView *)textView {
    if (!_textView) {
        _textView = [[YYTextView alloc] init];
        _textView.placeholderFont = XJFONTSET_R(15.0);
        _textView.placeholderText = @"请输入您的问题";
        _textView.font = XJFONTSET_R(15.0);
    }
    return _textView;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setupView {

    [self addSubview:self.div1];
    [self addSubview:self.iconIv];
    [self.div1 addSubview:self.nameLb];
    [self.div1 addSubview:self.countLb];
    
    [self addSubview:self.div2];
    [self.div2 addSubview:self.questionLb];
    [self.div2 addSubview:self.textView];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat k15 = 15.0;
    
    
    //h:100
    [self.div1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(k15);
        make.right.equalTo(self.mas_right).offset(-k15);
        make.top.equalTo(self.mas_top);
        make.height.mas_equalTo(100);
    }];
    [self.iconIv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self.div1);
        make.size.mas_equalTo(CGSizeMake(100, 100));
    }];
    
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconIv.mas_right).offset(10);
        make.top.equalTo(self.div1.mas_top);
        make.size.mas_equalTo(CGSizeMake(200, 30));
    }];
    [self.countLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconIv.mas_right).offset(10);
        make.bottom.equalTo(self.div1.mas_bottom).offset(-30);
        make.size.mas_equalTo(CGSizeMake(100, 30));
    }];
    
    
    //h:100
    [self.div2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.div1.mas_bottom).offset(5);
        make.left.equalTo(self.mas_left).offset(k15);
        make.right.equalTo(self.mas_right).offset(-k15);
        make.height.mas_equalTo(100);
    }];
    
    [self.questionLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.div2);
        make.top.equalTo(self.div2);
        make.height.mas_equalTo(30);
    }];
    
    [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.div2);
        make.top.equalTo(self.questionLb.mas_bottom);
        make.height.mas_equalTo(65);
    }];
}



#pragma mark - 赋值
- (void)setAfterM:(XJAfterSaleModel *)afterM {
    _afterM = afterM;
    
    UIImage *placeholderImg = [UIImage imageNamed:@"default_goods"];
    
    [self.iconIv sd_setImageWithURL:[NSURL URLWithString:afterM.cover] placeholderImage:placeholderImg];
    self.nameLb.text = afterM.goods_name;
    self.countLb.text = [NSString stringWithFormat:@"数量   %@",afterM.quantity];
}

@end
